package com.credithc.signature.job.utils;

import com.alibaba.fastjson.JSONObject;
import com.credithc.signature.common.po.FddConfig;
import com.credithc.signature.common.ro.GetExtSignPageRo;
import com.credithc.signature.common.ro.sign.GetExtBatchSignPageRo;
import com.credithc.signature.common.to.*;
import com.credithc.signature.common.utils.FddConfigMap;
import com.credithc.signature.common.utils.UUIDUtil;
import com.credithc.signature.job.ro.FddConfigRO;
import com.credithc.signature.job.service.FadadaSdkClient;
import com.fadada.lightapi.FDDSDKClient;
import com.fadada.lightapi.base.ReturnBase;
import com.fadada.lightapi.beans.conformity.register.AccountRegisterReq;
import com.fadada.lightapi.beans.conformity.register.AccountRegisterRsp;
import com.fadada.lightapi.beans.conformity.verfiy.VerCompanyRsp;
import com.fadada.lightapi.beans.conformity.verfiy.VerGetCompanyUrlReq;
import com.fadada.lightapi.beans.conformity.verfiy.VerGetPersonUrlReq;
import com.fadada.lightapi.beans.conformity.verfiy.VerGetUrlRsp;
import com.fadada.lightapi.beans.conformity.verfiy.info.AgentInfoReq;
import com.fadada.lightapi.beans.conformity.verfiy.info.BankInfoReq;
import com.fadada.lightapi.beans.conformity.verfiy.info.CompanyInfoReq;
import com.fadada.lightapi.beans.conformity.verfiy.info.LegalInfoReq;
import com.fadada.lightapi.beans.contract.*;
import com.fadada.lightapi.beans.customer.CustomerReq;
import com.fadada.lightapi.beans.customer.CustomerRsp;
import com.fadada.lightapi.beans.extsign.BatchSignAutoReq;
import com.fadada.lightapi.beans.extsign.BatchSignData;
import com.fadada.lightapi.beans.extsign.GetExtBatchSignPageReq;
import com.fadada.lightapi.beans.extsign.GetExtSignPageReq;
import com.fadada.lightapi.beans.signatureOperate.SignatureOperateReq;
import com.fadada.lightapi.beans.signatureOperate.SignatureOperateRsp;
import com.fadada.lightapi.beans.signauto.SignAutoReq;
import com.fadada.lightapi.beans.signauto.SignAutoRsp;
import com.fadada.lightapi.beans.template.TemplateReq;
import com.fadada.lightapi.beans.template.TemplateRsp;
import com.fadada.lightapi.beans.witness.ContractWitnessReq;
import com.fadada.lightapi.beans.witness.WitnessRsp;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

/**
 * @desc: 法大大接口调用工具<br />
 * @author: Jingbo Hu<br/>
 * @time：2020年07⽉09⽇<br/>
 * @version：v1.0.0<br>
 */
@Slf4j
public class FddClientUtil {


    /**
     * 注册接口
     *
     * @param openId      用户在接入方唯一标识
     * @param accountType 用户类型：1-个人，2-企业
     * @return
     */
    public static AccountRegisterRsp register(String openId, Integer accountType, String channelNo, String requestSn) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        AccountRegisterReq req = new AccountRegisterReq();
        req.setOpenId(openId);
        req.setAccountType(accountType);
        AccountRegisterRsp rsp = null;
        try {
            setFDDConfig(channelNo, requestSn);
            rsp = client.register(req);
        } catch (Exception e) {
            log.error("调用法大大【注册接口】发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return rsp;
    }

    /**
     * 将fdd配置放入threadlocal
     *
     * @param channelId
     * @param requestSn
     */
    private static void setFDDConfig(String channelId, String requestSn) {
        FddConfig fddConfig = FddConfigMap.getConfig().get(channelId);
        if (fddConfig == null) {
            log.info("根据渠道编号：{}未获取到configMap", channelId);
            throw new RuntimeException("未获取到configMap");
        }
        FddConfigRO fddConfigRO = new FddConfigRO();
        BeanUtils.copyProperties(fddConfig, fddConfigRO);
        fddConfigRO.setRequestSn(requestSn);
        GlobalVarManager.setGlobalVars(fddConfigRO);
    }

    /**
     * 获取个人实名认证地址
     *
     * @param personInfo
     * @return
     */
    public static VerGetUrlRsp getPersonUrl(FddPersonInfo personInfo, String channelNo, String requestSn) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        VerGetPersonUrlReq person = new VerGetPersonUrlReq();
        person.setCustomerId(personInfo.getCustomerId());
        person.setPageModify(personInfo.getPageModify());
        person.setVerifiedWay(personInfo.getVerifiedWay());
        person.setNotifyUrl(personInfo.getNotifyUrl());
        person.setReturnUrl(personInfo.getReturnUrl());
        person.setCustomerIdentNo(personInfo.getCustomerIdentNo());
        person.setCustomerIdentType(personInfo.getCustomerIdentType());
        person.setIdentFrontPath(personInfo.getIdentFrontPath());
        person.setMobile(personInfo.getMobile());
        person.setCustomerName(personInfo.getCustomerName());
        person.setCert_flag(personInfo.getCertFlag());
        VerGetUrlRsp rsp = null;
        try {
            setFDDConfig(channelNo, requestSn);
            rsp = client.verGetPersonUrl(person);
        } catch (Exception e) {
            log.error("调用法大大【获取个人实名认证地址】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return rsp;
    }

    /**
     * 获取企业实名认证地址
     *
     * @param companyInfoBody
     * @return
     */
    public static VerGetUrlRsp getCompanyUrl(FddCompanyInfo companyInfoBody, String channelNo, String requestSn) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        VerGetCompanyUrlReq company = new VerGetCompanyUrlReq();
        company.setCustomerId(companyInfoBody.getCustomerId());
        company.setPageModify(companyInfoBody.getPageModify());
        company.setVerifiedWay(companyInfoBody.getVerifiedWay());
        company.setmVerifiedWay(companyInfoBody.getMVerifiedWay());
        company.setNotifyUrl(companyInfoBody.getNotifyUrl());
        company.setReturnUrl(companyInfoBody.getReturnUrl());
        company.setCompanyPrincipalType(companyInfoBody.getCompanyPrincipalType());
        company.setCert_flag(companyInfoBody.getCertFlag());

        //设置企业信息
        if (companyInfoBody.getCompanyInfo() != null) {
            CompanyInfo companyInfo = companyInfoBody.getCompanyInfo();
            CompanyInfoReq companyInfoReq = new CompanyInfoReq();
            companyInfoReq.setCompany_name(companyInfo.getCompanyName());
            companyInfoReq.setCredit_image_path(companyInfo.getCreditImagePath());
            companyInfoReq.setCredit_no(companyInfo.getCreditNo());
            company.setCompanyInfo(companyInfoReq);
        }
        // 设置代理人信息
        if (companyInfoBody.getAgentInfo() != null) {
            AgentInfo agentInfo = companyInfoBody.getAgentInfo();
            AgentInfoReq agentInfoReq = new AgentInfoReq();
            agentInfoReq.setAgent_id(agentInfo.getAgentId());
            agentInfoReq.setAgent_id_front_path(agentInfo.getAgentIdFrontPath());
            agentInfoReq.setAgent_mobile(agentInfo.getAgentMobile());
            agentInfoReq.setAgent_name(agentInfo.getAgentName());
            company.setAgentInfo(agentInfoReq);
        }
        // 设置法人信息
        if (companyInfoBody.getLegalInfo() != null) {
            LegalInfo legalInfo = companyInfoBody.getLegalInfo();
            LegalInfoReq legalInfoReq = new LegalInfoReq();
            legalInfoReq.setLegal_id(legalInfo.getLegalId());
            legalInfoReq.setLegal_id_front_path(legalInfo.getLegalIdFrontPath());
            legalInfoReq.setLegal_mobile(legalInfo.getLegalMobile());
            legalInfoReq.setLegal_name(legalInfo.getLegalName());
            company.setLegalInfo(legalInfoReq);
        }
        // 设置对公账号信息
        if (companyInfoBody.getBankInfo() != null) {
            BankInfo bankInfo = companyInfoBody.getBankInfo();
            BankInfoReq bankInfoReq = new BankInfoReq();
            bankInfoReq.setBank_id(bankInfo.getBankId());
            bankInfoReq.setBank_name(bankInfo.getBankName());
            bankInfoReq.setSubbranch_name(bankInfo.getSubbranchName());
            company.setBankInfo(bankInfoReq);
        }

        VerGetUrlRsp rsp = null;
        try {
            setFDDConfig(channelNo, requestSn);
            rsp = client.verGetCompanyUrl(company);
        } catch (Exception e) {
            log.error("调用法大大【获取企业实名认证地址】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return rsp;
    }

    /**
     * 查询个人/企业实名认证状态
     *
     * @param serialNo    实名序列号，获取地址时返回
     * @param accountType 用户类型：1-个人，2 企业
     * @return
     */
    public static VerCompanyRsp verCompanyRsp(String serialNo, Integer accountType, String channelNo, String requestSn) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        VerCompanyRsp rsp = null;
        try {
            setFDDConfig(channelNo, requestSn);
            rsp = client.findVerifyInfo(serialNo, accountType);
        } catch (Exception e) {
            log.error("调用法大大【查询个人/企业实名认证状态】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return rsp;
    }

    /**
     * 编号证书申请
     *
     * @param customerId       客户编号--注册账号时返回
     * @param verifiedSerialno 实名认证序列号--获取实名认证地址时返回
     * @return
     */
    public static ReturnBase applyNumCert(String customerId, String verifiedSerialno, String channelNo, String requestSn) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        ReturnBase base = null;
        try {
            setFDDConfig(channelNo, requestSn);
            base = client.applyNumCert(customerId, verifiedSerialno);
        } catch (Exception e) {
            log.error("调用法大大【编号证书申请】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return base;
    }

    /**
     * 实名证书申请
     *
     * @param customerId       客户编号--注册账号时返回
     * @param verifiedSerialno 实名认证序列号--获取实名认证地址时返回
     * @return
     */
    public static ReturnBase applyCert(String customerId, String verifiedSerialno, String channelNo, String requestSn) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        ReturnBase base = null;
        try {
            setFDDConfig(channelNo, requestSn);
            base = client.applyCert(customerId, verifiedSerialno);
        } catch (Exception e) {
            log.error("调用法大大【编号证书申请】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return base;
    }

    /**
     * 通过UUID下载图片
     *
     * @param uuid 图片 uuid （查询实名信息时返回）
     * @return
     */
    public static String downImgWithUUID(String uuid, String channelNo, String requestSn) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        String url = null;
        try {
            setFDDConfig(channelNo, requestSn);
            url = client.downImgWithUUID(uuid);
        } catch (Exception e) {
            log.error("调用法大大【通过UUID下载图片】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return url;
    }


    /**
     * 合同模板上传
     *
     * @param templateId 模板id
     * @param docUrl     模板文件的HTTP协议URL
     * @param file       模板文件二进制流文件
     * @return
     */
    public static TemplateRsp uploadTemplet(String templateId, String docUrl, File file, String channelNo, String requestSn) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        TemplateReq req = new TemplateReq();
        req.setTemplate_id(templateId);
        if (file == null) {
            req.setDocUrl(docUrl);
        } else {
            req.setFile(file);
        }
        TemplateRsp rsp = null;
        try {
            setFDDConfig(channelNo, requestSn);
            rsp = client.uploadTemplate(req);
        } catch (Exception e) {
            log.error("调用法大大【合同模板上传】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return rsp;
    }

    /**
     * 上传合同
     *
     * @param contractId 合同 id
     * @param docTitle   合同标题
     * @param docType    文件类型.pdf
     * @param file       模板文件二进制流文件
     * @param docUrl     模板文件的 HTTP 协议 URL
     * @param validity   单位为毫秒的有效时间，格式为大于 0 的整数
     * @return
     */
    public static UploadContractRsp uploadContract(String contractId, String docTitle, String docType, File file, String docUrl, String validity, String channelNo, String requestSn) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        UploadContractReq req = new UploadContractReq();
        req.setContractId(contractId);
        req.setDocTitle(docTitle);
        req.setDocType(docType);
        UploadContractRsp rsp = null;
        try {
            if (file == null) {
                req.setFile(new File(docUrl));
            }
            if (StringUtils.isNotBlank(validity)) {
                req.setValidity(validity);
            }
            setFDDConfig(channelNo, requestSn);

            rsp = client.uploadContract(req);
        } catch (Exception e) {
            log.error("调用法大大【上传合同】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return rsp;
    }

    /**
     * 获取签章连接
     * @return
     */
    public static String getSignUrl(GetExtSignPageRo req){
        FDDSDKClient client = FadadaSdkClient.initClient();
        String url = null;
        try {
            setFDDConfig(req.getChannelNo(), req.getRequestSn());
            GetExtSignPageReq req1 = new GetExtSignPageReq();
            BeanUtils.copyProperties(req,req1);
            url = client.getSignPageUrl(req1);
        } catch (Exception e) {
            log.error("调用法大大【获取签章链接】接口发生异常......", e);
        }finally {
            GlobalVarManager.remove();
        }
        return url;
    }


    /**
     * 获取批量签章连接
     * @return
     */
    public static String getBatchSignUrl(GetExtBatchSignPageRo req){
        FDDSDKClient client = FadadaSdkClient.initClient();
        String url = null;
        try {
            setFDDConfig(req.getChannelNo(), req.getRequestSn());
            GetExtBatchSignPageReq req1 = new GetExtBatchSignPageReq();
            BeanUtils.copyProperties(req,req1);
            System.out.println(JSONObject.toJSONString(req1));
            System.out.println(JSONObject.toJSONString(req));
            url = client.getBatchSignPageUrl(req1);
        } catch (Exception e) {
            log.error("调用法大大【获取签章链接】接口发生异常......", e);
        }finally {
            GlobalVarManager.remove();
        }
        return url;
    }

    public static void main(String[] args) {
        FDDSDKClient client = FadadaSdkClient.initClient();
//        UploadContractRsp uploadContractRsp = uploadContract("cssczhq000002", "测试模板001", ".pdf", null, "C:/Users/DELL-3020/Downloads/0001.pdf", null, "LESSEE201900001020", "cssczhq000001");
//        System.out.println(uploadContractRsp);
        GetExtBatchSignPageReq req1 = new GetExtBatchSignPageReq();
        req1.setBatchId(UUIDUtil.getUUID());
        req1.setCustomerId("0C1CE68AA2F40D7298A5E713D791C062");
        req1.setNotifyUrl("www.baidu.com/callback/id");
        req1.setReturnUrl("www.baidu.com");
        req1.setClientUrl("http://118.26.173.86:8095");
        req1.setBatchTitle("测试批量手动签署");
        FddConfigRO fddConfigRO = new FddConfigRO();

        List<BatchSignData> signDatas = new ArrayList<>();
        BatchSignData signData1 = new BatchSignData();
        signData1.setContractId("3a0078b7084b45e3937f009b3120d78b");
        signData1.setKeywordStrategy("0");
        signData1.setSignKeyword("_马凯迪_");
        signData1.setTransactionId(UUIDUtil.getUUID());
        signDatas.add(signData1);

        BatchSignData signData2 = new BatchSignData();
        signData2.setContractId("ee90b2024c974938a4d0eda202450cc1");
        signData2.setKeywordStrategy("0");
        signData2.setSignKeyword("_马凯迪_");
        signData2.setTransactionId(UUIDUtil.getUUID());
        signDatas.add(signData2);

        BatchSignData signData3 = new BatchSignData();
        signData3.setContractId("7ac87287511a402cabdac670198fc902");
        signData3.setKeywordStrategy("0");
        signData3.setSignKeyword("_马凯迪_");
        signData3.setTransactionId(UUIDUtil.getUUID());
        signDatas.add(signData3);

        req1.setSignData(signDatas);
        GetExtBatchSignPageReq req2 = new GetExtBatchSignPageReq();
        BeanUtils.copyProperties(req1,req2);
        System.out.println(JSONObject.toJSONString(req2));
        System.out.println(JSONObject.toJSONString(req1));


        //BeanUtils.copyProperties(fddConfig, fddConfigRO);
        //fddConfigRO.setRequestSn(requestSn);
        fddConfigRO.setAppId("403452");
        fddConfigRO.setAppSecret("cAPWkpjWKejKePA0wsNRVn67");
        GlobalVarManager.setGlobalVars(fddConfigRO);

        String url = null;
        try {
            url = client.getBatchSignPageUrl(req1);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        System.out.println(url);
        System.out.println(JSONObject.toJSONString(req1));

    }

    /**
     * 获取有效合同查看/签署 token
     * 注意：有效期从调用该接口成功返回了 token  即生效，超过该有效期的 token  传值到合同查看或合同签署接口里会提示“地址已失效”。
     *
     * @param validity 单位为毫秒的有效时间，格式为大于 0 的整数
     * @param quantity 有效次数
     * @param type     token 类型 1:合同查看 2:合同签署
     * @return
     */
    public static GetUrlTokenRsp getUrlToken(String validity, String quantity, String type, String channelNo, String requestSn) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        GetUrlTokenReq rsq = new GetUrlTokenReq();
        rsq.setQuantity(validity);
        rsq.setValidity(quantity);
        rsq.setType(type);
        GetUrlTokenRsp rsp = null;
        try {
            setFDDConfig(channelNo, requestSn);
            rsp = client.GetUrlToken(rsq);
        } catch (Exception e) {
            log.error("调用法大大【获取有效合同查看/签署】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return rsp;
    }

    /**
     * 自动签署
     *
     * @param req ruletype: 2:按照传递的坐标信息签章；3：按照文字查找签章
     * @return
     */
    public static SignAutoRsp signAuto(SignAutoReq req, String channelNo, String requestSn) throws Exception {
        FDDSDKClient client = FadadaSdkClient.initClient();
        SignAutoRsp rsp = null;
        try {
            setFDDConfig(channelNo, requestSn);
            rsp = client.signAuto(req);
            if (!"1000".equals(rsp.getCode())){
                log.error("fadada自动签署失败：返回code={}，msg={}",rsp.getCode(), rsp.getMsg());
                throw new Exception(rsp.getMsg());
            }
        } catch (Exception e) {
            log.error("调用法大大【自动签署】接口发生异常......", e);
            throw e;
        } finally {
            GlobalVarManager.remove();
        }
        return rsp;
    }

    /**
     * 自动签署--批量
     *
     * @param signAutoList
     * @param batchId
     * @param batchTitle
     * @return
     */
    public static ReturnBase batchSignAuto(List<SignAutoReq> signAutoList, String batchId, String batchTitle, String channelNo, String requestSn) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        ReturnBase returnBase = null;
        try {
            setFDDConfig(channelNo, requestSn);
            BatchSignAutoReq req = new BatchSignAutoReq.Builder()
                    .batchId(batchId)
                    .batchTitle(batchTitle)
                    .signData(signAutoList)
                    .builder();
            returnBase = client.batchSignAuto(req);
        } catch (Exception e) {
            log.error("调用法大大【自动签署】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return returnBase;
    }

    /**
     * 合同归档接口
     *
     * @param contractId
     * @return
     */
    public static WitnessRsp witness(String contractId, String channelNo, String requestSn) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        ContractWitnessReq req = new ContractWitnessReq();
        req.setContractNum(contractId);
        WitnessRsp rsp = null;
        try {
            setFDDConfig(channelNo, requestSn);
            rsp = client.witness(req);
        } catch (Exception e) {
            log.error("调用法大大【合同归档】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return rsp;
    }

    /**
     * 用户信息修改
     *
     * @param customerId 客户编号
     * @param mobile     手机号码
     * @param email      邮箱地址
     * @return
     */
    public static CustomerRsp modifyCustomer(String customerId, String mobile, String email, String channelNo, String requestSn) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        CustomerReq req = new CustomerReq();
        req.setCustomerId(customerId);
        req.setEmail(mobile);
        req.setMobile(email);
        CustomerRsp rsp = null;
        try {
            setFDDConfig(channelNo, requestSn);
            rsp = client.modifyCustomer(req);
        } catch (Exception e) {
            log.error("调用法大大【用户信息修改】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return rsp;
    }

    /**
     * 合同下载
     *
     * @param contractId 合同编号
     * @return
     */
    public static ContractDownloadResponse contractDownload(String contractId, String channelNo, String requestSn) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        ContractDownloadRequest downloadRequest = new ContractDownloadRequest();
        downloadRequest.setContractId(contractId);
        ContractDownloadResponse res = null;
        try {
            setFDDConfig(channelNo, requestSn);
            res = client.contractDownload(downloadRequest);
        } catch (Exception e) {
            log.error("调用法大大【合同下载】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return res;
    }

    /**
     * 新增用户签章
     *
     * @param customerId         客户编号
     * @param signatureImgBase64 签章图片base64
     * @param signatureId        签章图片编号
     * @return
     */
    public static SignatureOperateRsp addSignature(String customerId, String signatureImgBase64, String signatureId, String channelNo, String requestSn) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        SignatureOperateReq req = new SignatureOperateReq();
        req.setCustomerId(customerId);
        req.setSignatureImgBase64(signatureImgBase64);
        req.setSignatureId(signatureId);
        SignatureOperateRsp rsp = null;
        try {
            setFDDConfig(channelNo, requestSn);
            rsp = client.addSignature(req);
        } catch (Exception e) {
            log.error("调用法大大【新增用户签章】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return rsp;
    }

    /**
     * 获取用户签章
     *
     * @return
     */
    public static SignatureOperateRsp querySignature(SignatureOperateReq req, String channelNo, String requestSn) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        SignatureOperateRsp rsp = null;
        try {
            setFDDConfig(channelNo, requestSn);
            rsp = client.querySignature(req);
        } catch (Exception e) {
            log.error("调用法大大【获取用户签章】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return rsp;
    }

    /**
     * 替换用户签章
     *
     * @param customerId         客户编号
     * @param signatureImgBase64 签章图片base64
     * @param signatureId        签章图片编号
     * @return
     */
    public static SignatureOperateRsp replaceSignature(String customerId, String channelNo, String requestSn, String signatureImgBase64, String signatureId) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        SignatureOperateReq req = new SignatureOperateReq();
        req.setCustomerId(customerId);
        req.setSignatureImgBase64(signatureImgBase64);
        req.setSignatureId(signatureId);
        SignatureOperateRsp rsp = null;
        try {
            setFDDConfig(channelNo, requestSn);
            rsp = client.replaceSignature(req);
        } catch (Exception e) {
            log.error("调用法大大【替换用户签章】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return rsp;
    }

    /**
     * 删除用户签章
     *
     * @param customerId         客户编号
     * @param signatureImgBase64 签章图片base64
     * @param signatureId        签章图片编号
     * @return
     */
    public static SignatureOperateRsp removeSignature(String customerId, String channelNo, String requestSn, String signatureImgBase64, String signatureId) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        SignatureOperateReq req = new SignatureOperateReq();
        req.setCustomerId(customerId);
        req.setSignatureImgBase64(signatureImgBase64);
        req.setSignatureId(signatureId);
        SignatureOperateRsp rsp = null;
        try {
            setFDDConfig(channelNo, requestSn);
            rsp = client.removeSignature(req);
        } catch (Exception e) {
            log.error("调用法大大【删除用户签章】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return rsp;
    }

    /**
     * 设置用户默认章
     *
     * @param customerId         客户编号
     * @param signatureImgBase64 签章图片base64
     * @param signatureId        签章图片编号
     * @return
     */
    public static SignatureOperateRsp defaultSignature(String customerId, String channelNo, String requestSn, String signatureImgBase64, String signatureId) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        SignatureOperateReq req = new SignatureOperateReq();
        req.setCustomerId(customerId);
        req.setSignatureImgBase64(signatureImgBase64);
        req.setSignatureId(signatureId);
        SignatureOperateRsp rsp = null;
        try {
            setFDDConfig(channelNo, requestSn);
            rsp = client.defaultSignature(req);
        } catch (Exception e) {
            log.error("调用法大大【设置用户默认章】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return rsp;
    }

    /**
     * 查询实名认证状态
     *
     * @param transactionNo
     * @param accountType
     * @return
     */
    public static VerCompanyRsp findVerifyInfo(String transactionNo, Integer accountType, String channelNo, String requestSn) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        VerCompanyRsp verifyInfo = null;
        try {
            setFDDConfig(channelNo, requestSn);
            verifyInfo = client.findVerifyInfo(transactionNo, accountType);
        } catch (Exception e) {
            log.error("调用法大大【查询实名认证状态】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return verifyInfo;
    }

    /**
     * 查询合同状态
     */
    public static ContractStatusRsp getContractStatus(String contractId, String channelNo, String requestSn) {
        FDDSDKClient client = FadadaSdkClient.initClient();
        ContractStatusRsp contractStatus = null;
        try {
            setFDDConfig(channelNo, requestSn);
            contractStatus = client.getContractStatus(contractId);
        } catch (Exception e) {
            log.error("调用法大大【查询合同状态】接口发生异常......", e);
        } finally {
            GlobalVarManager.remove();
        }
        return contractStatus;
    }
}
